#ifdef __KERNEL__
#include <linux/string.h>
#else
#include <string.h>
#endif
#include "modes_local.h"

#if defined(__GNUC__) && !defined(STRICT_ALIGNMENT)
typedef size_t size_t_aX __attribute((__aligned__(1)));
#else
typedef size_t size_t_aX;
#endif

/*
 * The input and output encrypted as though 128bit ofb mode is being used.
 * The extra state information to record how much of the 128bit block we have
 * used is contained in *num;
 */
void CRYPTO_ofb128_encrypt(const unsigned char* in, unsigned char* out,
                           size_t len, const void* key, unsigned char ivec[16],
                           int* num, block128_f block)
{
    unsigned int n;
    size_t       l = 0;

    n = *num;
    while (l < len) {
        if (n == 0) {
            (*block)(ivec, ivec, key);
        }
        out[l] = in[l] ^ ivec[n];
        ++l;
        n = (n + 1) % 16;
    }

    *num = n;
}
